package com.yonyou.sto.modules.ums.util;

import cn.hutool.core.util.StrUtil;
import com.yonyou.sto.modules.ims.model.ImsInvoiceItem;
import com.yonyou.sto.modules.ums.model.UmsNcCusttax;
import com.yonyou.sto.modules.ums.model.UmsNcMategrade;

public class ConfigNameUtil {

    public static String getCusttaxItem(UmsNcCusttax umsNcCusttax,UmsNcMategrade umsNcMategrade, ImsInvoiceItem item){
        StringBuilder stringBuilder=new StringBuilder();//拼接客户物料名称
        boolean flag1 = false;
        if ("1".equals(umsNcCusttax.getCusttax1())){//税收分类名称
            if (StrUtil.isNotBlank(umsNcCusttax.getTaxname())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(umsNcCusttax.getTaxname());//税收分类名称
                flag1 = true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax2())){//NC物料分类
            if (StrUtil.isNotBlank(umsNcMategrade.getName())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(umsNcMategrade.getName());//NC物料分类
                flag1 = true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax3())){//NC物料名称
            if (StrUtil.isNotBlank(item.getProductName())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getProductName());//NC物料名称
                flag1 = true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax4())){//型号
            if (StrUtil.isNotBlank(item.getProductSpec())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getProductSpec());//型号
                flag1 = true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax5())){//客户物料编码
            if (StrUtil.isNotBlank(item.getCustmatcode())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getCustmatcode());//客户物料编码
                flag1 = true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax6())){//客户物料名称
            if (StrUtil.isNotBlank(item.getDef4())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getDef4());//客户物料名称
            }
        }

        StringBuilder stringBuilder1=new StringBuilder();//拼接规格型号
        boolean flag2 = false;
        //拼接规格型号
        if ("1".equals(umsNcCusttax.getCusttax7())){//NC物料分类
            if (StrUtil.isNotBlank(umsNcMategrade.getName())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(umsNcMategrade.getName());//NC物料分类
                flag2=true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax8())){//NC物料名称
            if (StrUtil.isNotBlank(item.getProductName())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getProductName());//NC物料编码
                flag2=true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax9())){//型号
            if (StrUtil.isNotBlank(item.getProductSpec())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getProductSpec());//型号
                flag2=true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax10())){//客户物料编码
            if (StrUtil.isNotBlank(item.getCustmatcode())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getCustmatcode());//客户物料编码
                flag2=true;
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax11())){//客户物料名称
            if (StrUtil.isNotBlank(item.getDef4())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getDef4());//客户物料名称
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax14())){//NC物料规格
            if (StrUtil.isNotBlank(item.getDef5())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getDef5());//NC物料规格
            }
        }
        if ("1".equals(umsNcCusttax.getCusttax15())){//税收分类名称
            if (StrUtil.isNotBlank(umsNcCusttax.getTaxname())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(umsNcCusttax.getTaxname());//税收分类名称
            }
        }
        String custMateName = stringBuilder.toString();
        if (StrUtil.isEmpty(custMateName)){
            if (StrUtil.isNotBlank(umsNcMategrade.getName())){
                custMateName=umsNcMategrade.getName();
            }
        }
        item.setCustmatname(custMateName);
        item.setDef3(stringBuilder1.toString());
        /*if(StrUtil.isNotBlank(umsNcCusttax.getTaxcode())){
            item.setProductSpec(umsNcCusttax.getTaxcode());
        }else if (StrUtil.isNotBlank(umsNcMategrade.getTaxcode())){
            item.setProductSpec(umsNcMategrade.getTaxcode());
        }*/
        //if (StrUtil.isNotEmpty(stringBuilder1.toString())){
            item.setProductSpec(stringBuilder1.toString());
        //}
        if ("1".equals(umsNcCusttax.getDef9())){
            custMateName="";
        }
        if ("1".equals(umsNcCusttax.getDef10())){
            item.setProductSpec("");
        }
        item.setProductUnit(umsNcCusttax.getCompany());
        item.setProductSn(umsNcCusttax.getTaxcode());//设置税收分类编码
        if("1".equals(umsNcCusttax.getCusttax16())){//客户物料名称自定义值
            item.setCustmatname(umsNcCusttax.getDef11());
        }
        if("1".equals(umsNcCusttax.getCusttax17())){//客户物料名称自定义值
            item.setProductSpec(umsNcCusttax.getDef12());
        }
        return custMateName;
    }

    public static String getMateItem(UmsNcMategrade umsNcMategrade,ImsInvoiceItem item){
        StringBuilder stringBuilder=new StringBuilder();//拼接
        boolean flag1= false;
        //拼接客户物料名称
        if ("1".equals(umsNcMategrade.getCusttax1())){//税收分类名称
            if (StrUtil.isNotBlank(umsNcMategrade.getTaxname())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(umsNcMategrade.getTaxname());//物料信息的税收分类
                flag1 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax2())){//物料分类名称
            if (StrUtil.isNotBlank(umsNcMategrade.getName())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(umsNcMategrade.getName());//物料信息的NC物料分类名称
                flag1 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax3())){//NC物料名称
            if (StrUtil.isNotBlank(item.getProductName())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getProductName());//物料信息的NC物料名称
                flag1 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax4())){//型号
            if (StrUtil.isNotBlank(item.getProductSpec())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getProductSpec());//型号
                flag1 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax5())){//客户物料编码
            if (StrUtil.isNotBlank(item.getCustmatcode())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getCustmatcode());//客户物料编码
                flag1 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax6())){//客户物料名称
            if (StrUtil.isNotBlank(item.getDef4())){
                if (flag1){
                    stringBuilder.append(" ");
                }
                stringBuilder.append(item.getDef4());//客户物料名称
            }
        }

        StringBuilder stringBuilder1=new StringBuilder();//拼接
        boolean flag2 = false;
        //拼接规格型号
        if ("1".equals(umsNcMategrade.getCusttax7())){//NC物料分类主键
            if (StrUtil.isNotBlank(umsNcMategrade.getName())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(umsNcMategrade.getName());//NC物料分类主键
                flag2 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax8())){//NC物料名称
            if (StrUtil.isNotBlank(item.getProductName())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getProductName());//NC物料名称
                flag2 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax9())){//型号
            if (StrUtil.isNotBlank(item.getProductSpec())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getProductSpec());//型号
                flag2 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax10())){//客户物料编码
            if (StrUtil.isNotBlank(item.getCustmatcode())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getCustmatcode());//客户物料编码
                flag2 = true;
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax11())){//客户物料名称
            if (StrUtil.isNotBlank(item.getDef4())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getDef4());//客户物料名称
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax12())){//NC物料规格
            if (StrUtil.isNotBlank(item.getDef5())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(item.getDef5());//NC物料规格
            }
        }
        if ("1".equals(umsNcMategrade.getCusttax13())){//税收分类名称
            if (StrUtil.isNotBlank(umsNcMategrade.getTaxname())){
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append(umsNcMategrade.getTaxname());//税收分类名称
            }
        }
        String custMateName = stringBuilder.toString();
        if (StrUtil.isEmpty(custMateName)){
            if (StrUtil.isNotBlank(umsNcMategrade.getName())){
                custMateName=umsNcMategrade.getName();
            }
        }
        item.setCustmatname(custMateName);
        //if (StrUtil.isNotEmpty(stringBuilder1.toString())&&StrUtil.isBlank(item.getProductSpec())){
            item.setProductSpec(stringBuilder1.toString());
        //}

        if("1".equals(umsNcMategrade.getCusttax14())){//客户物料名称自定义值
            item.setCustmatname(umsNcMategrade.getDef11());
        }
        if("1".equals(umsNcMategrade.getCusttax15())){//客户物料名称自定义值
            item.setProductSpec(umsNcMategrade.getDef12());
        }
        return custMateName;
    }

    public static String getConfigMate(UmsNcMategrade umsNcMategrade,UmsNcCusttax umsNcCusttax){
        StringBuilder stringBuilder=new StringBuilder();//拼接
        boolean flag1 = false;
        //拼接客户物料名称
        if ("1".equals(umsNcMategrade.getCusttax1())){//税收分类名称
            if (flag1){
                stringBuilder.append(" ");
            }
                stringBuilder.append("税收分类名称");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax2())){//NC物料名称
            if (flag1){
                stringBuilder.append(" ");
            }
                stringBuilder.append("NC物料分类");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax3())){//NC物料编码
            if (flag1){
                stringBuilder.append(" ");
            }
                stringBuilder.append("NC物料名称");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax4())){//型号
            if (flag1){
                stringBuilder.append(" ");
            }
                stringBuilder.append("型号");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax5())){//客户物料编码
            if (flag1){
                stringBuilder.append(" ");
            }
                stringBuilder.append("客户物料编码");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax6())){//客户物料名称
            if (flag1){
                stringBuilder.append(" ");
            }
                stringBuilder.append("客户物料名称");//客户物料名称
        }
        StringBuilder stringBuilder1=new StringBuilder();//拼接
        boolean flag2 = false;
        //拼接规格型号
        if ("1".equals(umsNcMategrade.getCusttax7())){//税收分类名称
            if (flag2){
                stringBuilder1.append(" ");
            }
                stringBuilder1.append("NC物料分类");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax8())){//NC物料名称
                if (flag2){
                    stringBuilder1.append(" ");
                }
                stringBuilder1.append("NC物料名称");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax9())){//NC物料编码
            if (flag2){
                stringBuilder1.append(" ");
            }
                stringBuilder1.append("型号");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax10())){//型号
            if (flag2){
                stringBuilder1.append(" ");
            }
                stringBuilder1.append("客户物料编码");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcMategrade.getCusttax11())){//客户物料名称
            if (flag2){
                stringBuilder1.append(" ");
            }
                stringBuilder1.append("客户物料名称");//客户物料名称
        }
        String custMateName = stringBuilder.toString();
        String string = stringBuilder1.toString();
        if (StrUtil.isEmpty(custMateName)){
            if (StrUtil.isNotBlank(umsNcMategrade.getCode())){
                custMateName=umsNcMategrade.getCode();
            }
        }
        umsNcCusttax.setDef5(custMateName);
        umsNcCusttax.setDef6(string);
        if ("1".equals(umsNcCusttax.getDef9())){//客户物料名称
            umsNcCusttax.setDef9("空值");//客户物料名称
        }
        if ("1".equals(umsNcCusttax.getDef10())){//客户物料名称
            umsNcCusttax.setDef10("空值");//客户物料名称
        }

        if("1".equals(umsNcMategrade.getCusttax14())){//客户物料名称自定义值
            umsNcCusttax.setDef5(umsNcMategrade.getDef11());
        }
        if("1".equals(umsNcMategrade.getCusttax15())){//客户物料名称自定义值
            umsNcCusttax.setDef6(umsNcMategrade.getDef12());
        }
        return custMateName;
    }

    public static String getConfigCusttax(UmsNcCusttax umsNcCusttax){
        StringBuilder stringBuilder=new StringBuilder();//拼接
        boolean flag1 = false;
        //拼接客户物料名称
        if ("1".equals(umsNcCusttax.getCusttax1())){//税收分类名称
            if (flag1){
                stringBuilder.append(" ");
            }
            stringBuilder.append("税收分类名称");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax2())){//NC物料名称
            if (flag1){
                stringBuilder.append(" ");
            }
            stringBuilder.append("NC物料分类");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax3())){//NC物料编码
            if (flag1){
                stringBuilder.append(" ");
            }
            stringBuilder.append("物料分类名称");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax4())){//型号
            if (flag1){
                stringBuilder.append(" ");
            }
            stringBuilder.append("型号");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax5())){//客户物料编码
            if (flag1){
                stringBuilder.append(" ");
            }
            stringBuilder.append("客户物料编码");//物料信息的税收分类
            flag1 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax6())){//客户物料名称
            if (flag1){
                stringBuilder.append(" ");
            }
            stringBuilder.append("客户物料名称");//客户物料名称
        }
        StringBuilder stringBuilder1=new StringBuilder();//拼接
        boolean flag2 = false;
        //拼接规格型号
        if ("1".equals(umsNcCusttax.getCusttax7())){//税收分类名称
            if (flag2){
                stringBuilder1.append(" ");
            }
            stringBuilder1.append("NC物料分类名称");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax8())){//NC物料名称
            if (flag2){
                stringBuilder1.append(" ");
            }
            stringBuilder1.append("物料分类名称");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax9())){//NC物料编码
            if (flag2){
                stringBuilder1.append(" ");
            }
            stringBuilder1.append("型号");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax10())){//型号
            if (flag2){
                stringBuilder1.append(" ");
            }
            stringBuilder1.append("客户物料编码");//物料信息的税收分类
            flag2 = true;
        }
        if ("1".equals(umsNcCusttax.getCusttax11())){//客户物料名称
            if (flag2){
                stringBuilder1.append(" ");
            }
            stringBuilder1.append("客户物料名称");//客户物料名称
        }
        String custMateName = stringBuilder.toString();
        String string = stringBuilder1.toString();
        if (StrUtil.isEmpty(custMateName)){
            custMateName="NC物料分类名称";
        }
        umsNcCusttax.setDef5(custMateName);
        umsNcCusttax.setDef6(string);
        if ("1".equals(umsNcCusttax.getDef9())){//客户物料名称
            custMateName="空值";//客户物料名称
        }
        if ("1".equals(umsNcCusttax.getDef10())){//客户物料名称
            umsNcCusttax.setDef6("空值");//客户物料名称
        }

        if("1".equals(umsNcCusttax.getCusttax16())){//客户物料名称自定义值
            custMateName=umsNcCusttax.getDef11();
        }
        if("1".equals(umsNcCusttax.getCusttax17())){//客户物料名称自定义值
            umsNcCusttax.setDef6(umsNcCusttax.getDef12());
        }
        return custMateName;
    }
}
